home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
vbjigsaw.zip
/
JIGSAW.TXT
< prev
next >
Wrap
Text File
|
1991-05-30
|
22KB
|
676 lines
DefInt A-Z
Declare Function BitBlt Lib "Gdi" (ByVal destHdc, ByVal X, ByVal Y, ByVal w, ByVal h, ByVal srcHdc, ByVal srcX, ByVal srcY, ByVal Rop As Long)
Declare Function CreateRectRgn Lib "Gdi" (ByVal X1, ByVal Y1, ByVal X2, ByVal Y2)
Declare Function SetRectRgn Lib "Gdi" (ByVal hRgn, ByVal X1, ByVal Y1, ByVal X2, ByVal Y2)
Declare Function SelectClipRgn Lib "Gdi" (ByVal Hdc, ByVal hRgn)
Declare Function CombineRgn Lib "Gdi" (ByVal hDestRgn, ByVal hSrcRgn1, ByVal hSrcRgn2, ByVal nCombineMode)
Const SRCCOPY = &HCC0020
Const SRCAND = &H8800C6
Const SRCINVERT = &H660046
Const NOTSRCCOPY = &H330008
Const SRCINVERTANDDEST = &H220B24
Const RGN_AND = 1
Const RGN_DIFF = 4
Const NULLREGION = 1
Const TRUE = -1
Const FALSE = 0
Const MODAL = 1
Const MID_OPEN = 0
Const MID_CLIPBOARD = 1
Const MID_EXIT = 3
Const MID_SCRAMMBLE = 0
Const MID_SOLVE = 1
Const MID_ANIMATE = 2
Const MID_PIECES_TO_FOREGROUND = 3
Const MID_SHOW_SCRAMMBLING = 5
Const MID_SCRAMMBLE_ON_OPEN = 6
Const MID_CIRCLES_AND_OTHERS = 1
Const MID_ELIPSES_AND_OTHERS = 2
Const MID_ANGELS_AND_STARS = 3
Const MID_CIRCLES_IN_SQUARES = 4
Dim TotalPieces As Integer
Dim PuzzleSize As Integer
Dim PieceHeight As Integer
Dim PieceWidth As Integer
Dim MovingPiece As Integer
Dim LastMouseX As Integer
Dim LastMouseY As Integer
Dim MaskNeeded As Integer
Dim Solved As Integer
Dim Region1 As Integer
Dim Region2 As Integer
Dim Region3 As Integer
Dim Region4 As Integer
Dim Piece As PIECEINFO
Dim Pieces() As PIECEINFO
Dim Priority() As Integer
Sub Form_Load ()
Region1 = CreateRectRgn(0, 0, 0, 0)
Region2 = CreateRectRgn(0, 0, 0, 0)
Region3 = CreateRectRgn(0, 0, 0, 0)
Region4 = CreateRectRgn(0, 0, 0, 0)
PuzzleSize = 5
Menu_Stop.Visible = FALSE
End Sub
Sub Set_Piece_Priority (Piece As Integer)
Temp = Priority(Piece)
For I = Piece To 1 Step -1
Priority(I) = Priority(I - 1)
Next
Priority(0) = Temp
End Sub
Sub Display_A_Piece (destHdc, Piece)
DestX = Pieces(Priority(Piece)).X
DestY = Pieces(Priority(Piece)).Y
If MaskNeeded Then
R = BitBlt(Pic_FinalPiece.Hdc, 0, 0, PieceWidth, PieceHeight, Pic_PuzzleImage.Hdc, DestX, DestY, SRCCOPY)
R = BitBlt(Pic_FinalPiece.Hdc, 0, 0, PieceWidth, PieceHeight, Pic_PieceMask.Hdc, 0, 0, SRCAND)
R = BitBlt(Pic_FinalPiece.Hdc, 0, 0, PieceWidth, PieceHeight, Pic_PieceImage.Hdc, 0, 0, SRCINVERT)
R = BitBlt(destHdc, DestX, DestY, PieceWidth, PieceHeight, Pic_FinalPiece.Hdc, 0, 0, SRCCOPY)
Else
R = BitBlt(destHdc, DestX, DestY, PieceWidth, PieceHeight, Pic_Bitmap.Hdc, Pieces(Priority(Piece)).HomeX, Pieces(Priority(Piece)).HomeY, SRCCOPY)
End If
End Sub
Sub Menu_OptionsSelection_Click (Index As Integer)
Pic_Work.MousePointer = 11
Select Case Index
Case MID_SCRAMMBLE
Scrammble_Puzzle
Case MID_SOLVE
Solve_Puzzle
Case MID_ANIMATE
Animate_Puzzle
Case MID_PIECES_TO_FOREGROUND
Bring_Pieces_To_Foreground
Case MID_SHOW_SCRAMMBLING, MID_SCRAMMBLE_ON_OPEN
Menu_OptionsSelection(Index).Checked = Not Menu_OptionsSelection(Index).Checked
End Select
Pic_Work.MousePointer = 0
End Sub
Sub Menu_FileSelection_Click (Index As Integer)
Picture = LoadPicture()
Select Case Index
Case MID_OPEN
OpenFile.Show MODAL
If OpenFile.File1.ListIndex >= 0 Then Picture = LoadPicture(OpenFile.File1.FileName)
Case MID_CLIPBOARD
Picture = ClipBoard.GetData()
Case MID_EXIT
Unload JigSaw
End Select
If Picture Then
Menu_Options.Enabled = TRUE
Menu_Pieces.Enabled = TRUE
Menu_Hint.Enabled = TRUE
Pic_Work.Visible = TRUE
Screen.MousePointer = 11
Prepare_Bitmap (Menu_OptionsSelection(MID_SCRAMMBLE_ON_OPEN).Checked)
Screen.MousePointer = 0
Pic_Window.Refresh
End If
End Sub
Sub Prepare_Bitmap (Scrammble)
Pic_Bitmap.Picture = Picture
Pic_Bitmap.Picture = Pic_Bitmap.Image
PieceWidth = Pic_Bitmap.Width / PuzzleSize
PieceHeight = Pic_Bitmap.Height / PuzzleSize
Pic_PuzzleImage.Cls
Pic_PuzzleImage.Move 0, 0, Pic_Bitmap.Width, Pic_Bitmap.Height
Pic_Work.Move 0, 0, Pic_Bitmap.Width, Pic_Bitmap.Height
Pic_Mask.Move 0, 0, Pic_Bitmap.Width, Pic_Bitmap.Height
Pic_Mask.Cls
Form_Resize
Randomize Timer
TotalPieces = 24
If MaskNeeded Then
Pic_PieceImage.Move 0, 0, PieceWidth, PieceHeight
Pic_PieceMask.Move 0, 0, PieceWidth, PieceHeight
Pic_FinalPiece.Move 0, 0, PieceWidth, PieceHeight
Select Case MaskNeeded
Case MID_CIRCLES_AND_OTHERS
Create_Circles_Mask
Case MID_ELIPSES_AND_OTHERS
Create_Elipses_Mask
Case MID_ANGELS_AND_STARS
Create_Angel_And_Stars_Mask
Case MID_CIRCLES_IN_SQUARES
TotalPieces = 31
Create_Circles_In_Squares_Mask
End Select
End If
ReDim Pieces(TotalPieces) As PIECEINFO
ReDim Priority(TotalPieces) As Integer
If (MaskNeeded > 0) And (MaskNeeded <> MID_CIRCLES_IN_SQUARES) Then
For Y = 0 To PuzzleSize - 2
For X = 0 To PuzzleSize - 2
I = TotalPieces - (Y * (PuzzleSize - 1) + X)
Pieces(I).HomeX = X * PieceWidth + PieceWidth / 2
Pieces(I).HomeY = Y * PieceHeight + PieceHeight / 2
Pieces(I).X = Pieces(I).HomeX
Pieces(I).Y = Pieces(I).HomeY
Priority(I) = I
Next X
Next Y
End If
For Y = 0 To PuzzleSize - 1
For X = 0 To PuzzleSize - 1
I = (PuzzleSize ^ 2 - 1) - (Y * PuzzleSize + X)
For Z = 0 To Abs(MaskNeeded = MID_CIRCLES_IN_SQUARES)
Pieces(I + Z * 16).HomeX = X * PieceWidth
Pieces(I + Z * 16).HomeY = Y * PieceHeight
Pieces(I + Z * 16).X = Pieces(I).HomeX
Pieces(I + Z * 16).Y = Pieces(I).HomeY
Priority(I + Z * 16) = I + Z * 16
Next Z
Next X
Next Y
Select Case MaskNeeded
Case 0, 4
Outline_Circles_In_Squares
Case 1
Case 2
Case 3
End Select
If Scrammble Then
Scrammble_Puzzle
Else
Solved = TRUE
R = BitBlt(Pic_PuzzleImage.Hdc, 0, 0, Pic_Bitmap.Width, Pic_Bitmap.Height, Pic_Bitmap.Hdc, 0, 0, SRCCOPY)
Pic_Work.Refresh
End If
End Sub
Sub Form_Unload (Cancel As Integer)
End
End Sub
Sub Form_Resize ()
Pic_Work.Move 0, 0
HScroll1.Move 0, ScaleHeight - HScroll1.Height, ScaleWidth - VScroll1.Width
VScroll1.Move ScaleWidth - VScroll1.Width, 0, VScroll1.Width, ScaleHeight - HScroll1.Height
Pic_ScrollBarJoint.Move VScroll1.Left, HScroll1.Top
Pic_Window.Move 0, 0, VScroll1.Left, HScroll1.Top
HScroll1.Enabled = Pic_Window.Width < Pic_Bitmap.Width
VScroll1.Enabled = Pic_Window.Height < Pic_Bitmap.Height
If VScroll1.Enabled Then
VScroll1.Value = 0
VScroll1.Max = Abs(Pic_Window.Height - Pic_Bitmap.Height)
VScroll1.LargeChange = VScroll1.Max \ 10
End If
If HScroll1.Enabled Then
HScroll1.Value = 0
HScroll1.Max = Abs(Pic_Window.Width - Pic_Bitmap.Width)
HScroll1.LargeChange = HScroll1.Max \ 10
End If
End Sub
Sub HScroll1_Change ()
' Pic_Work.Left is set to the Negative of the value since
' as you scroll the Scrollbar to the Right, the display
' should move to the Left, showing more of the right
' of the display, and vice-versa when scrolling to the
' left
Pic_Work.Left = -HScroll1.Value
End Sub
Sub VScroll1_Change ()